﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using System.Data;
using AspNetCs.Model;

public partial class AjaxXml_InsertMemorial_Numid : BasePage
{
    /// <summary>
    /// 纪念馆馆号
    /// </summary>
    protected string NumId = "";
    /// <summary>
    /// 陵园ID
    /// </summary>
    protected int lyid = 0;
    /// <summary>
    /// X坐标
    /// </summary>
    protected int MouseX = 0;
    /// <summary>
    /// Y坐标
    /// </summary>
    protected int MouseY = 0;


    protected int Result = -1;
    protected void Page_Load(object sender, EventArgs e)
    {


        try
        {
            if (Base_GetLoginInfo.GetUserID <= 0)
            {
                Response.Write(-6);//用户未登录
            }

            NumId = Request["Num"].ToString();
            lyid = StringHelper.isNumber_int(Request["lyid"].ToString());
            MouseX = StringHelper.isNumber_int(Request["x"].ToString());
            MouseY = StringHelper.isNumber_int(Request["y"].ToString());
            if (NumId == "")
            {
                Response.Write(-3);//馆号为空
                Response.End();

            }

            if (lyid == 0)
            {
                Response.Write(-4);//陵园ID不能为空
                Response.End();

            }




            bool isfalse = StringHelper.Str_IsInt(NumId.ToString(), out NumId);
            if (!isfalse)
            {
                Result = -2;//馆号输入有误
            }
            else
            {
                DataTable dt = Memorial_Bll.CreateNew.GetDataTable(" Where  Numid='" + NumId + "'");
                Result = dt.Rows.Count;
                if (Result > 0)
                {
                    List<Cemetery_AddNumId_Model> list = Cemetery_AddNumId_Bll.CreateNew.GetData(" Cemeteryid=" + lyid + "  and  Numid='" + NumId + "'");
                    if (list.Count <= 0)
                    {
                        Cemetery_Model CemeMd = Cemetery_Bll.CreateNew.GetModel(lyid);

                        Cemetery_AddNumId_Model mdl = new Cemetery_AddNumId_Model();
                        mdl.NetIP = StringHelper.Ip();
                        mdl.NumId = NumId;
                        mdl.PositionX = MouseX;
                        mdl.PositionY = MouseY;
                        mdl.TempleId = CemeMd.TempleId;
                        mdl.CemeteryNames = CemeMd.Names;
                        mdl.CemeteryId = lyid;
                        mdl.UserId = Base_GetLoginInfo.GetUserID;
                        Result = Cemetery_AddNumId_Bll.CreateNew.Add(mdl);
                    }
                    else
                    {
                        Response.Write(-5);//当前数据已经存在
                        Response.End();
                    }

                }
            }
        }
        catch
        {
            Result = -1;
        }


        Response.Write(Result);
    }
}
